package com.yxzx.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
@ApiModel(value = "全局统一返回结果")
public class YxzxResult {
    @ApiModelProperty("返回是否成功")
    private boolean success;
    @ApiModelProperty("返回状态码")
    private Integer code;
    @ApiModelProperty("返回消息")
    private String message;

    @ApiModelProperty("返回数据")
    private Map<String, Object> data = new HashMap<String, Object>();

    private YxzxResult(){}

    public static YxzxResult ok(){
        YxzxResult r = new YxzxResult();
        r.setSuccess(true);
        r.setCode(ResultCode.OK);
        r.setMessage("成功");
        return r;
    }

    public static YxzxResult error(){
        YxzxResult r = new YxzxResult();
        r.setSuccess(false);
        r.setCode(ResultCode.ERROR);
        r.setMessage("失败");
        return r;
    }

    public YxzxResult message(String message){
        this.setMessage(message);
        return this;
    }

    public YxzxResult code(Integer code){
        this.setCode(code);
        return this;
    }

    public YxzxResult data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public YxzxResult data(Map<String, Object> map){
        this.setData(map);
        return this;
    }
}
